"Bank Application"
"Translated from a Java version"
"-----------Customer.st----------"
Object subclass: Customer [	
	|name|
	
    Customer class [
        new: theName [
            ^super new init: theName
        ]
    ]
    
    init: theName [
        name:=theName
    ]
    
    toString [
    	^name
    ]
    
]

"-----------Customer.st----------okay"
"-----------Account.st----------"
Object subclass: Account [
	|number customer balance|		
	
	accrue: rate [
		^self subclassResponsibility
	]
	
	balance [ 
		^balance 
	]
	
	deposit: amount [ 
		balance:=balance+amount 
	]
	
	withdraw: amount [ 
		balance:=balance-amount 
	]
	
	toString [
		^number, ':', (customer toString), ':', (balance asString)
	]
	
]

"-------------Account.st--------------------"
"-------------SavingsAccount.st-------------"
Account subclass: SavingsAccount [
	|interest|
	
	SavingsAccount class [
        newWithNumber: num customer: cust balance: bal [
        	^super new initWithNumber: num customer: cust balance: bal
        ]
    ]
    
    init [
		interest:=0
    ]
    
    initWithNumber: num customer: cust balance: bal [
    	self init.
    	number := num.
    	customer := cust.
    	balance :=  bal
    ]
    
    accrue: rate [
    	balance:= balance + (balance*rate).
    	interest:= interest + (balance*rate)
    ]
]
"-------------SavingsAccount.st-------------"
"-------------CheckingAccount.st-------------"
Account subclass: CheckingAccount [
	
	CheckingAccount class [
        newWithNumber: num customer: cust balance: bal [
        	^super new initWithNumber: num customer: cust balance: bal
        ]
    ]
    
    initWithNumber: num customer: cust balance: bal [
    	number := num.
    	customer := cust.
    	balance :=  bal
    ]
    
    accrue: rate [    ]
    
]



"-------------CheckingAccount.st-------------"
"-------------Bank.st-------------"
Object subclass: Bank [
	| accounts |
	
	Bank class [
		new [
			^super new init
		]
	]
	
	init [
		accounts:= Set new
	]
	
	add: acc [
		accounts add: acc
	]
	
	accrue: rate [
		accounts do: [ :x | x accrue: rate] 
	]
	
	toString [
		|s|
		s := ''.
		accounts do: [ :x | s:= (s, (x toString), (Character nl asString))].
		^s  	
	]
]

"-------------Bank.st-------------"
"---------------------------------"
"Correspond to main method in Java"

|Bank| bank := Bank new.
|Customer| c := Customer new: 'Ann'.
(bank add: (CheckingAccount newWithNumber: '01001' customer: c balance: 100.00)).
(bank add: (SavingsAccount newWithNumber: '01002' customer: c balance: 200.00)).
bank accrue: 0.02.
"bank printNl." 
(bank toString) printNl.


